<script
	lang="ts"
	setup
>
import { processComplaintPut } from '@/api'
import EmptyModal from '@/components/EmptyModal.vue'
import type { IProcessComplaintPut } from '@/typed/request'
import { type FormInst, type FormRules } from 'naive-ui'
import { computed, onMounted, ref, watch } from 'vue'

interface IProps {
	show: boolean;
	data?: any;
	width?: number | string;
}

const formRef = ref<FormInst | null>(null)
const emit = defineEmits(['update:show', 'update:list'])
const props = withDefaults(defineProps<IProps>(), {
	width: 500
})
const initForm: ITenantPost = {
    id:'',
    operResult: '',
	status: null,
};

const loading = ref(false)
const modalForm = ref<ITenantPost>({ ...initForm })
const modalTitle = computed(() => {
	return '处理反馈'
})

const rules: FormRules = {
    operResult: [{
		required: true,
		message: '请输入反馈结果',
		trigger: ['blur', 'input']
	}],
    status: [{
        required: true,
        message: '请选择处理状态',
        trigger: 'change'
    }]
}



const isEdit = computed(() => !!props.data?.id)

async function onAdd() {
	formRef.value?.validate(async (errors) => {
		if (!errors) {
			loading.value = true
            modalForm.value.id = props.data.id;
			const { code } = await processComplaintPut(modalForm.value as IProcessComplaintPut)
			loading.value = false
			if (code === 200) {
				window.$message.success('保存成功')
				modalForm.value = { ...initForm }

				emit('update:list')
				emit('update:show', false)
			}
		}
	})
}

function onCancel() {
	if (!loading.value) {
		emit('update:show', false)
		modalForm.value = { ...initForm }
	}
}
const roleOptions = ref<any[]>([])


</script>

<template>
	<EmptyModal
		:show="show"
		:width="600"
		:title="modalTitle"
		@confirm="onAdd"
		:on-negative-click="onCancel"
		:on-close="onCancel"
		:on-positive-click="onAdd"
		:positive-button-props="{ loading }"
	>
		<n-form
			ref="formRef"
			:model="modalForm"
			label-placement="left"
			label-width="140"
			:rules="rules"
		>
			<n-form-item label="状态" path="status">
				<n-radio-group v-model:value="modalForm.status">
					<n-radio value="1">解决</n-radio>
					<n-radio value="2">作废</n-radio>
				</n-radio-group>
			</n-form-item>

			<n-form-item
				label="反馈结果"
				path="operResult"
			>
				<n-input
					type="textarea"
					placeholder="请输入备注信息"
					v-model:value="modalForm.operResult"
				/>
			</n-form-item>
		</n-form>
	</EmptyModal>
</template>

<style
	lang="less"
	scoped
>
.n-upload {
	width: fit-content;
}
</style>
